package ar.edu.caece.pl.asem.model.impl.treeelements;

import java.util.ArrayList;
import java.util.List;

import ar.edu.caece.pl.asem.model.INodeData;

public abstract class AbstractElement implements INodeData {

	protected String label;
	public List<AbstractElement> children;
	public AbstractElement parent;
	public String code = "";
	public String place;
	public String envName;
	public String name;

	public abstract boolean equals(Object obj);

	public String getLabel() {
		return this.label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	@Override
	public String toString() {
		return this.getLabel();
	}

	public List<AbstractElement> getChildren() {
		if (this.children == null) {
			return new ArrayList<AbstractElement>();
		}
		return this.children;
	}

	public AbstractElement getParent() {
		return parent;
	}

	public void setParent(AbstractElement parent) {
		this.parent = parent;
	}

	public void setChildren(List<AbstractElement> children) {
		this.children = children;
	}

	public void generateASMCode() {
		for (int i = 0; i < this.getChildren().size(); i++) {
			this.getChildren().get(i).generateASMCode();
			String code = this.getChildren().get(i).code;
			if (!"".equals(code)) {
				this.code = this.code + code;
				if(this.getChildren().get(i) instanceof ReturnType){
					i++;
				}
			}
		}
	}

	public String getPlace() {
		return "";
	}

	public String getEnvName() {
		return envName;
	}

	public void setEnvName(String envName) {
		this.envName = envName;
	}

	public void setPlace(String place) {
		this.place = place;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
